
var app = getApp()
// const { fill } = require("core-js/fn/array")
var axios = require("../../utils/core")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        check: true,
        level: "",
        levels: "",
        filePath: [], //本地地址
        filePath_1: [], //本地地址
        xythumb: '', //后端解析后的图片地址
        zfthumb: '', //后端解析后的图片地址
        openid: '',
        levelslist:[],
        list: [{
                level: 1,
                price: '689',
                target:"创客"
            },
            {
                level: 2,
                price: '9999',
                target:"门店"
            },
            {
                level: 3,
                price: '19999',
                target:"总代理"
            },
            {
                level: 4,
                price: '39999',
                target:"区域代理"
            },
        ]
    },
    check: function () {
        var check = this.data.check
        this.setData({
            check: check ? false : true
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    btn: function () {
        if (!this.data.check) {
            wx.showModal({
                cancelColor: 'cancelColor',
                title: '提示',
                content: "请先勾选用户协议哦",

            })
        } else if (this.data.xythumb == '' && this.data.zfthumb == '') {
            wx.showModal({
                cancelColor: 'cancelColor',
                title: '提示',
                content: '协议或者支付凭证未上传'
            })
        } else {
            axios.post("goods.djts_tj", {
                openid: this.data.openid,
                uplevelid: this.data.levels,
                xythumb: this.data.xythumb,
                zfthumb: this.data.zfthumb
            }, ((e) => {
                if (e.status == -1) {
                    wx.showModal({
                        cancelColor: 'cancelColor',
                        title: '提示',
                        content: '已经在加急' + e.message + '了,请不要急哦!',
                        success(res) {
                            if (res.confirm) {
                                setTimeout(() => {
                                    wx.switchTab({
                                        url: '/pages/operation/index',
                                    })
                                }, 1000)

                            }
                        }

                    })
                } else if (e.status == 2) {
                    wx.showToast({
                        title: e.message,
                        duration: 2000
                    })
                } else if (e.status == 3) {
                    wx.showToast({
                        title: e.message,
                        duration: 2000
                    })
                }
            }))
        }
    },
    //上传图片
    chooseImage: function (e) {
        var that = this;
        wx.chooseImage({
            count: 1,
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                console.log(res);
                that.setData({
                    filePath: res.tempFilePaths
                });
                console.log(that.data.filePath);
                wx.uploadFile({
                    url: "https://zzsl.sctqmt.com/app/ewei_shopv2_api.php?i=1&r=goods.upload&comefrom=wxapp",
                    filePath: that.data.filePath[0],
                    name: 'file',
                    formData: {
                        openid: that.data.openid
                    },
                    success(res) {
                        var data = JSON.parse(res.data)
                        data = data.img_url.url
                        console.log(data);
                        that.setData({
                            xythumb: data
                        })
                    }
                })
            }
        })
    },
    chooseImage_1: function (e) {
        var that = this;
        wx.chooseImage({
            count: 1,
            sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
            sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
            success: function (res) {
                // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
                console.log(res);
                that.setData({
                    filePath_1: res.tempFilePaths
                });
                wx.uploadFile({
                    url: "https://zzsl.sctqmt.com/app/ewei_shopv2_api.php?i=1&r=goods.upload&comefrom=wxapp",
                    filePath: res.tempFilePaths[0],
                    name: 'file',
                    formData: {
                        openid: that.data.openid
                    },
                    success(res) {
                        var data = JSON.parse(res.data)
                        data = data.img_url.url
                        console.log(data);
                        that.setData({
                            zfthumb: data
                        })
                    }
                })
            }
        })
    },
    onLoad: function (e) {
        this.setData({
            level: e.level,
            levels: e.levels
        })
        var openid = wx.getStorageSync('openid')
        this.setData({
            openid: openid
        })
        axios.post("goods.djts", {}, ((el) => {
            this.setData({
                levelslist: el
            })
        }))

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})